#include <iostream>
using std::cout;
using std::endl;

class Complex{
public:
    Complex(double real,double image)
    : _real(real)
    , _image(image)
    {
        cout << "Complex(double,double)" << endl;
    }

    void print() const{
        if(0 == _real && 0 == _image){
            cout << 0 << endl;
        }
        else if(0 == _real){
            cout << _image << "i" << endl;
        }
        else{
            cout << _real;
            if(_image > 0){
                cout << "+" << _image << "i" << endl;
            }
            else if(_image < 0){
                cout << "-" << -1 * _image << "i" << endl;
            }
            else{
                cout << endl;
            }
        }
    }

    friend Complex & operator+=(Complex & lhs,const Complex & rhs);
    friend Complex operator+(const Complex & lhs,const Complex & rhs);
private:
    double _real;
    double _image;
};

Complex & operator+=(Complex & lhs,const Complex & rhs)
{
    lhs._real += rhs._real;
    lhs._image += rhs._image;
    return lhs;
}

/* int operator+(const int & x,const int & y){ */
/*     return x - y; */
/* } */

/* Complex & operator$(Complex & lhs,const Complex & rhs) */
/* { */
/*     return lhs; */
/* } */

//运算符重载之普通友元函数
Complex operator+(const Complex & lhs,const Complex & rhs){
    return Complex(lhs._real + rhs._real,
                   lhs._image + rhs._image);
}

void test0(){
    Complex c1(1,2);
    Complex c2(4,5);
    c1 += c2;
    c1 +=(c1 += c2);
    c1.print();

    /* c1$c2; */
    c1.print();
}

int main(void){
    test0();
    return 0;
}
